﻿namespace Pisces
{
	/**
	 * ui元素
	 * 生命周期:  init --> loaded --> awake --> show --> update --> destroy
     * created by wangqiang
    **/
	public abstract class AbstractUIElement : InterfaceUILiftcycle
	{
		/// <summary>
		/// UI的view对象(view负责绑定引擎的各种UI组件以及一些显示的处理)
		/// </summary>
		private AbstractUIView view;

		public AbstractUIView View
		{
			get => view;
			set => view = value;
		}

		/// <summary>
		/// UI被创建时调用
		/// </summary>
		public virtual void onInit()
		{
		}

		/// <summary>
		/// UI加载完资源后调用
		/// </summary>
		public virtual void onLoaded()
		{
		}

		/// <summary>
		/// UI可以开始工作时调用
		/// </summary>
		public virtual void onAwake()
		{
		}

		/// <summary>
		/// UI完成初始化开始走显示逻辑时调用
		/// </summary>
		public virtual void onShow()
		{
			if (view != null)
			{
				view.onShow();
			}
		}
		
		/// <summary>
		/// UI隐藏时调用
		/// </summary>
		public virtual void onHide()
		{
			if (view != null)
			{
				view.onHide();
			}
		}

		/// <summary>
		/// 更新调用
		/// </summary>
		/// <param name="deltaTime"></param>
		public virtual void onUpdate(float deltaTime)
		{
		}

		/// <summary>
		/// 销毁时调用
		/// </summary>
		public virtual void onDestroy()
		{
		}
		
	}
	
}